package com.zeh.billing.controller;


import com.zeh.billing.config.CommonResult;
import com.zeh.billing.entity.*;
import com.zeh.billing.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zeh
 * @since 2021-08-20
 */
@RestController
@RequestMapping("/admin")
@CrossOrigin
@Api(tags = "管理员 接口")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public CommonResult login(@RequestBody @Validated LoginDo admin){
        CommonResult login = adminService.login(admin);
        return login;
    }

    @GetMapping("info")
    public CommonResult  info(){
        InfoToken in = new InfoToken();
        in.setAvatar("https://picsum.photos/seed/picsum/200/300");
        in.setRoles("[admin]");
        return CommonResult.success(in);
    }

    @PostMapping("register")
    @ApiOperation("注册")
    public CommonResult register(@RequestBody @Validated AdminDto admin){
        CommonResult register = adminService.register(admin);
        return  register;
    }

}

